<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="学生编号">
              <a-input placeholder="请输入学生编号" v-model="queryParam.stuId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="简历状态">
              <j-dict-select-tag placeholder="请选择简历状态" v-model="queryParam.resumeState" dictCode="resume_state"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
               <a-menu-item>
                <a @click="showDrawer();AuditShowList(record.stuId)">审核记录</a>
              </a-menu-item>
               <a-menu-item v-if='record.resumeState!=1&&record.resumeState!=3'>
                <a @click="updateResumeState(record.id,record.stuId,1)">审核通过</a>
              </a-menu-item>
               <a-menu-item v-if='record.resumeState==0'>
                <a @click="updateResumeState(record.id,record.stuId,2)">审核拒绝</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <a-drawer
      title="审核记录"
      :width="800"
      placement="left"
      :closable="false"
      :visible="visible2"
      :after-visible-change="afterVisibleChange"
      @close="onClose"
    >
      <template>
        <a-table :columns="columns2" :data-source="auditList" bordered>
          <template slot="name" slot-scope="text">
            <a>{{ text }}</a>
          </template>
        </a-table>
      </template>

    </a-drawer>

    <div>
      <a-modal
        title="审核意见"
        :visible="visible"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
      >
        <a-form-model-item label="拒绝原因">
          <j-editor v-model="audit.auditOpinion" />
        </a-form-model-item>
      </a-modal>
    </div>
    <employment-resume-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EmploymentResumeModal from './modules/EmploymentResumeModal'
  import {initDictOptions, filterDictText,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import Area from '@/components/_util/Area'
  import '@/assets/less/TableExpand.less'
  import { getAction, postAction } from '../../../api/manage'
  const columns2 = [
    {
      title: '审核人',
      dataIndex: 'createBy',
    },
    {
      title: '审核类别',
      dataIndex: 'auditCategory',
    },
    {
      title: '审核情况',
      dataIndex: 'auditStatus',
      customRender: (text, record, index) => {
       if (text==1){
         return "已通过";
       }else{
         return "未通过";
       }
      }
    },
    {
      title: '审核意见',
      dataIndex: 'auditOpinion',
    },
    {
      title: '审核时间',
      dataIndex: 'createTime',
    },
  ];

  export default {
    name: "EmploymentResumeList",
    mixins:[JeecgListMixin],
    components: {
      EmploymentResumeModal
    },

    data () {
      return {

        columns2,
        visible:false,
        visible2:false,
        ModalText: 'Content of the modal',
        confirmLoading: false,

        description: '简历管理页面',
        // 表】
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'学生名称',
            align:"center",
            dataIndex: 'stuId',
            customRender: (text, record, index) => {
              for (let i = 0; i < this.stuList.length; i++) {//遍历学生表信息
                if (this.stuList[i].stuId==text){//判断学生编号和签订人编号
                  return this.stuList[i].stuName;//返回该编号对应的学生名称
                }
              }
            }
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'employmentResumeSex',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.sexDictOptions, text);
            },
          },
          {
            title:'出生年月',
            align:"center",
            dataIndex: 'employmentResumeBirthday',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'当前身份',
            align:"center",
            dataIndex: 'employmentResumeIdentity',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.identityDictOptions, text);
            },
          },
          {
            title:'户口所在地',
            align:"center",
            dataIndex: 'currentResidence',
           /* scopedSlots: {customRender: 'pcaSlot'}*/
          },
          {
            title:'现居住地',
            align:"center",
            dataIndex: 'newCity',
            /*scopedSlots: {customRender: 'pcaSlot'}*/
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'tel'
          },
          {
            title:'电子邮箱',
            align:"center",
            dataIndex: 'mailbox'
          },
          {
            title:'简历附件',
            align:"center",
            dataIndex: 'resumeAttachment',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title: '简历状态',
            align: "center",
            dataIndex: 'resumeState',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.resumeStateDictOptions, text);
            },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/resume/employmentResume/list",
          delete: "/resume/employmentResume/delete",
          deleteBatch: "/resume/employmentResume/deleteBatch",
          exportXlsUrl: "/resume/employmentResume/exportXls",
          importExcelUrl: "resume/employmentResume/importExcel",
          stuUrl:"/stu/stu/getStuList",
          updateResumeStateUrl:"/resume/employmentResume/updateResumeState",
          auditAddUrl:'/audit/auditRecords/add',
          auditShowUrl:'/audit/auditRecords/auditShowById'
        },
        dictOptions:{},
        superFieldList:[],
        resumeStateDictOptions:{},
        identityDictOptions:{},
        sexDictOptions:{},
        stuList:{},
        audit:{foreignKey:null,auditCategory:null,auditStatus:null,auditOpinion:null,},
        auditList:{},
      }
    },
    created() {
      this.pcaData = new Area()
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {

      //查询该学生的审核记录
      AuditShowList(stuId){
        getAction(this.url.auditShowUrl+'?stuId='+stuId).then((res)=>{
          this.auditList = res.result;
        })
      },

      //抽屉
      afterVisibleChange(val) {
        console.log('visible', val);
      },
      showDrawer() {
        this.visible2 = true;
      },
      onClose() {
        this.visible2 = false;
      },

      //添加审核记录
      auditAdd(){
        postAction(this.url.auditAddUrl,this.audit).then((res)=>{
          if (res.success){
            this.loadData();
            this.$message.success("审核提交成功！")
          }else {
            this.$message.warning("审核提交失败！")
          }
        })
      },

      handleOk(e) {
        this.confirmLoading = true;
        setTimeout(() => {
          this.visible = false;
          this.confirmLoading = false;
        }, 2000);
       this.auditAdd();
      },
      handleCancel(e) {
        console.log('Clicked cancel button');
        this.visible = false;
        this.auditAdd();
      },

      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initDictConfig() {
        //初始化字典
        //简历状态
        initDictOptions('resume_state').then((res) => {
          if (res.success) {
            this.resumeStateDictOptions = res.result;
          }
        });

        //当前身份
        initDictOptions('essential_information_identity').then((res) => {
          if (res.success) {
            this.identityDictOptions = res.result;
          }
        });

        //性别
        initDictOptions('sex').then((res) => {
          if (res.success) {
            this.sexDictOptions = res.result;
          }
        });

        //查询学生表中的全部数据
        this.$http.get(this.url.stuUrl).then((res)=>{
          if (res.success){
            this.stuList = res.result;
          }
        });
      },

      //修改简历状态 -审核 1通过，2拒绝
      updateResumeState(id,stuId,stateNum){
        this.audit.foreignKey = stuId;
        this.audit.auditCategory = '简历审核';
        this.audit.auditStatus = stateNum;
        this.$http.get(this.url.updateResumeStateUrl+'?id='+id+'&stateNum='+stateNum).then((res)=>{
          if (res.success){
            if (stateNum==1){
              //审核记录表添加审核记录
              this.auditAdd();
            }
            if(stateNum==2) {//不通过
              this.visible = true;//弹窗
            }
          }else {
            this.$message.warning("审核提交失败！")
          }
        })
      },

      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_search',value:'stuId',text:'学生编号',dictTable:"STU", dictText:'STU_NAME', dictCode:'STU_ID'})
        fieldList.push({type:'int',value:'employmentResumeSex',text:'性别',dictCode:'sex'})
        fieldList.push({type:'date',value:'employmentResumeBirthday',text:'出生年月'})
        fieldList.push({type:'int',value:'employmentResumeIdentity',text:'当前身份',dictCode:'essential_information_identity'})
        fieldList.push({type:'string',value:'currentResidence',text:'户口所在地'})
        fieldList.push({type:'string',value:'newCity',text:'现居住地'})
        fieldList.push({type:'string',value:'tel',text:'联系方式',dictCode:''})
        fieldList.push({type:'string',value:'mailbox',text:'电子邮箱',dictCode:''})
        fieldList.push({type:'string',value:'teacherAdvise',text:'老师建议',dictCode:''})
        fieldList.push({type:'string',value:'resumeAttachment',text:'简历附件',dictCode:''})
        fieldList.push({type:'int',value:'resumeState',text:'简历状态',dictCode:'resume_state'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  th.column-money,
  td.column-money {
    text-align: right !important;
  }
</style>
